package com.cuit.dao.impl;

import com.cuit.pojo.Doctor;
import com.cuit.dao.MangerDao;
import com.cuit.pojo.Manger;

import java.util.List;

public class MangerDaoImpl extends BaseDao implements MangerDao {
    @Override
    public Manger queryUserByUsernameAndPassword(String username, String password) {
        String sql = "select `id`,`username`,`psw`from manager where username=? and psw=?";
        return queryForOne(Manger.class, sql, username, password);
    }

    @Override
    public Integer queryForPageTotalCount() {
        String sql = "select count(*) from doctors";
        Number count = (Number) queryForSingleValue(sql);
        return count.intValue();
    }

    @Override
    public List<Doctor> queryDoctorByPage(int begin, int pageSize) {
        String sql = "select `d_name` as name," +
                "`d_id` as id," +
                "`d_password` as  password," +
                "`d_age` as age," +
                "`d_sex` as `sex`," +
                "`d_grade` as grade," +
                "`d_department` as department," +
                "`d_profile` as profile " +
                "from doctors " +
                "order by `d_id` desc " +
                "limit ?,?";
        return queryForList(Doctor.class, sql, begin, pageSize);
    }

    @Override
    public void addDoctor(Doctor doctor) {
        String sql = "insert into doctors(`d_password`) values(?)";
        update(sql,doctor.getPassword());
    }

    @Override
    public void deleteDoctorById(int id) {
        String sql="delete from doctors where `d_id` = ?";
        update(sql,id);
    }
}
